package com.chenyun.system.vo;


import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.apache.commons.lang3.StringUtils;

import java.util.List;


/**
 * 路由显示信息
 *
 * @author ruoyi
 */
@Builder
@AllArgsConstructor
public class MetaVo {
    /**
     * 设置该路由在侧边栏和面包屑中展示的名字
     */
    private String title;

    /**
     * 设置该路由的图标，对应路径src/assets/icons/svg
     */
    private String icon;

    /**
     * 设置为true，则不会被 <keep-alive>缓存
     */
    private boolean noCache;
    //是否在菜单中显示,兼容pure-admin
    private boolean showLink;
    //和noCache一样
    private Boolean keepAlive;

    /**
     * 内链地址（http(s)://开头）
     */
    private String link;

    /**
     * 外链的打开方式
     */
    private String target;
    private String query;
    private String perms;

    // 菜单排序，值越高排的越后（只针对顶级路由）
    private int rank;
    //是否显示父菜单,只有一个子节点时才设置
    private Boolean showParent = null;
    //内嵌的ifream地址
    private String frameSrc;
    //页面级别权限设置
    private List<String> roles = null;
    //按钮级别
    private List<String> auths = null;
    /**
     * 跳转方式
     */
    private String targetType;

    public Boolean getKeepAlive() {
        return keepAlive;
    }

    public void setKeepAlive(Boolean keepAlive) {
        this.keepAlive = keepAlive;
    }

    public Boolean getShowParent() {
        return showParent;
    }

    public void setShowParent(Boolean showParent) {
        this.showParent = showParent;
    }

    public String getFrameSrc() {
        return frameSrc;
    }

    public void setFrameSrc(String frameSrc) {
        this.frameSrc = frameSrc;
    }

    public List<String> getRoles() {
        return roles;
    }

    public void setRoles(List<String> roles) {
        this.roles = roles;
    }

    public List<String> getAuths() {
        return auths;
    }

    public void setAuths(List<String> auths) {
        this.auths = auths;
    }

    public MetaVo() {
    }

    public MetaVo(String title, String icon) {
        this.title = title;
        this.icon = icon;
    }

    public MetaVo(String title, String icon, boolean noCache) {
        this.title = title;
        this.icon = icon;
        this.noCache = noCache;
    }

    public MetaVo(String title, String icon, String link) {
        this.title = title;
        this.icon = icon;
        this.link = link;
    }

    public MetaVo(String title, String icon, boolean noCache, String link) {
        this.title = title;
        this.icon = icon;
        this.noCache = noCache;
        if (ishttp(link)) {
            this.link = link;
        }
    }

    public MetaVo(String title, String icon, boolean noCache, String link, String target, String targetType) {
        this.title = title;
        this.icon = icon;
        this.noCache = noCache;
        this.link = link;
        this.target = target;
        this.targetType = targetType;
    }

    public MetaVo(String title, String icon, boolean noCache, String link, String target, String targetType, String query, String perms) {
        this.title = title;
        this.icon = icon;
        this.noCache = noCache;
        this.link = link;
        this.target = target;
        this.query = query;
        this.perms = perms;
        this.targetType = targetType;
    }

    boolean ishttp(String link) {
        return StringUtils.startsWithAny(link, "http://", "https://");

    }

    public boolean isNoCache() {
        return noCache;
    }

    public void setNoCache(boolean noCache) {
        this.noCache = noCache;
    }

    public String getTitle() {
        return title;
    }

    public void setTitle(String title) {
        this.title = title;
    }

    public String getIcon() {
        return icon;
    }

    public void setIcon(String icon) {
        this.icon = icon;
    }

    public String getLink() {
        return link;
    }

    public void setLink(String link) {
        this.link = link;
    }

    public String getTarget() {
        return target;
    }

    public void setTarget(String target) {
        this.target = target;
    }

    public String getTargetType() {
        return targetType;
    }

    public void setTargetType(String targetType) {
        this.targetType = targetType;
    }

    public String getQuery() {
        return query;
    }

    public void setQuery(String query) {
        this.query = query;
    }

    public String getPerms() {
        return perms;
    }

    public void setPerms(String perms) {
        this.perms = perms;
    }

    public boolean isShowLink() {
        return showLink;
    }

    public void setShowLink(boolean showLink) {
        this.showLink = showLink;
    }

    public int getRank() {
        return rank;
    }

    public void setRank(int rank) {
        this.rank = rank;
    }
}
